package com.cdg.godtools;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Process;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }

    private Button btnTest;
    private Button btnClear;
    private Button btnSend;
    private Button btnRegist;
    private Button btnUnRegist;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Example of a call to a native method
        TextView tv = findViewById(R.id.sample_text);
        tv.setText(stringFromJNI());
        btnTest = findViewById(R.id.btn_test);
        btnSend = findViewById(R.id.btn_send);
        btnClear = findViewById(R.id.btn_clear);
        btnRegist = findViewById(R.id.btn_regist_signal);
        btnUnRegist = findViewById(R.id.btn_unregist_signal);


        btnTest.setOnClickListener(this);
        btnSend.setOnClickListener(this);
        btnClear.setOnClickListener(this);
        btnRegist.setOnClickListener(this);
        btnUnRegist.setOnClickListener(this);
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_send:
                int myPid = Process.myPid();
                sendSignalQuiet(myPid,3);
                break;
            case R.id.btn_clear:

                break;
            case R.id.btn_test:
                doNativeTest();
                break;
            case R.id.btn_regist_signal:
                registSignalNative();
                break;
            case R.id.btn_unregist_signal:
                doNativeTest();
                break;
            default:
                break;
        }

    }

    public static final native void sendSignalQuiet(int pid, int signal);
    public static final native void doNativeTest();
    public static final native void registSignalNative();
    public static final native void unRegistSignalNative();




}